﻿using System.Reflection;

namespace Borg
{
    internal class UnplugFromSlotsTask : Task<ExtensionInfo>
    {
        private readonly ExtensionInfo _unpluggingEi;

        public override string Name
        {
            get
            {
                return _unpluggingEi == null
                    ? string.Format("UnplugFromSlots({0})", obj.Name)
                    : string.Format("UnplugFromSlots({0}, {1})", obj.Name, _unpluggingEi.Name);
            }
        }

        public UnplugFromSlotsTask(ExtensionInfo obj, ExtensionInfo unpluggingEi,
            uint taskGroupId, Assembly initiator)
            : base(obj, taskGroupId, initiator)
        {
            _unpluggingEi = unpluggingEi;
        }

        public override void Execute()
        {
            if (_unpluggingEi == null)
                obj.InternalUnplugFromSlots(initiator, false);
            else
                obj.InternalUnplugFromSlots(_unpluggingEi, initiator, false);
        }

        public override string ToString()
        {
            return _unpluggingEi == null
                ? string.Format("{0}: {1}.InternalUnplugFromSlots()", taskGroupId, obj)
                : string.Format("{0}: {1}.InternalUnplugFromSlots({2})", taskGroupId, obj, _unpluggingEi);
        }
    }
}

